<?php
	class TeamAction extends CommonAction{
		
		public function index(){
			$model = M('Archives');
			$map = array('type'=> 'team');
			$count = $model->where($map)->count('id');
	        import("ORG.Util.Page");
			$p = new Page($count, C('LIST_BOARD_NUMBER'));
	        //分页查询数据
	        $list = $model
	        	->where($map)->order('id DESC')
	        	->limit($p->firstRow . ',' . $p->listRows)->select();
			
			$this->assign('list', $list);
	        $this->assign("page", $p->show());
	        Cookie::set('_currentUrl_', __SELF__);
			$this->display();
		}
		
		public function _before_index(){
			$this->getCategoryOption('team');
		}
		
		public function edit(){
			$model = M('Archives');
	        //$id = $_REQUEST[$model->getPk()];
	        $vo = $model->find($_GET['id']);
	        $this->assign('vo', $vo);
	        $this->display();
		}
		
		public function insert(){
			$model = D ( 'Archives' );
			if (false === $model->create ()) {
				$this->error ( $model->getError () );
			}
			//保存当前数据对象
			$list = $model->add ();
			if ($list!==false) { //保存成功
				$this->checkSession();
				$this->assign ( 'jumpUrl', Cookie::get ( '_currentUrl_' ) );
				$this->success ('新增成功!');
			} else {
				//失败提示
				$this->error ('新增失败!');
			}
		}
		
		public function update(){
			$model = D ( 'Archives' );
			if (false === $model->create ()) {
				$this->error ( $model->getError () );
			}
			// 更新数据
			$list = $model->save ();
			if (false !== $list) {
				$this->checkSession();
				//成功提示
				$this->assign ( 'jumpUrl', Cookie::get ( '_currentUrl_' ) );
				$this->success ('编辑成功!');
			} else {
				//错误提示
				$this->error ('编辑失败!');
			}
		}
		
		public function _before_add()
		{
			$this->getCategoryOption('team');
		}
		
		public function _before_edit(){
			$this->getCategoryOption('team', $_GET['cid']);
		}
		
		public function moveCatelog(){
			$model = D('Archives');
			if ( $_POST['movecatelog'] ){
				if ( count( $_POST['list'] ) > 0 ){
					$where['id'] = array( 'in', $_POST['list'] );
					if ( $model->where( $where )->setField('cid',$_POST['cid']) ){
						$this->success( '转移成功' );
					}else{
						$this->error( '转移失败' );
					}
				}
			}
		}
	}
